C      := gcc
CFLAGS := -g -O0 -Wall -I ./include/ 

# wildcard: "*.c" -> "a.c b.c c.c..."
DEPANDCOMs := $(wildcard ./src/*.c)
DEPANDSERs := $(wildcard ./src/server/*.c)
DEPANDCLIs := $(wildcard ./src/client/*.c)

# patsubst: "%.c" -> "%.o"
OBJCOMs    := $(patsubst %.c, %.o, $(DEPANDCOMs))
OBJSERs    := $(patsubst %.c, %.o, $(DEPANDSERs))
OBJCLIs    := $(patsubst %.c, %.o, $(DEPANDCLIs))

# -l sqlite3 should be put in the last position
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@ -l sqlite3

ALL: server client
	@echo "Make jobs accomplish."

server: $(OBJCOMs) $(OBJSERs)
	$(CC) $(CFLAGS) $^ -o $@ -l sqlite3

client: $(OBJCOMs) $(OBJCLIs)
	$(CC) $(CFLAGS) $^ -o $@ -l sqlite3 

.PHONY: clean
clean:
	@rm -rf $(OBJCOMs) $(OBJSERs) $(OBJCLIs) ./server ./client ./mydatabase.db
	@echo "Clean jobs accomplish."

